package com.ruoyi.web.service.impl;

import java.util.HashMap;
import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.mapper.ClinicalNewsMapper;
import com.ruoyi.web.domain.ClinicalNews;
import com.ruoyi.web.service.IClinicalNewsService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 临床招募新闻Service业务层处理
 * 
 * @author drx
 * @date 2024-04-22
 */
@Service
public class ClinicalNewsServiceImpl implements IClinicalNewsService 
{
    @Resource
    private ClinicalNewsMapper clinicalNewsMapper;

    /**
     * 查询临床招募新闻
     * 
     * @param id 临床招募新闻主键
     * @return 临床招募新闻
     */
    @Override
    public ClinicalNews selectClinicalNewsById(Long id)
    {
        ClinicalNews clinicalNews = clinicalNewsMapper.selectClinicalNewsById(id);
        return clinicalNews;
    }

    /**
     * 查询临床招募新闻列表
     * 
     * @param clinicalNews 临床招募新闻
     * @return 临床招募新闻
     */
    @Override
    public List<ClinicalNews> selectClinicalNewsList(ClinicalNews clinicalNews)
    {
        return clinicalNewsMapper.selectClinicalNewsList(clinicalNews);
    }

    /**
     * 新增临床招募新闻
     * 
     * @param clinicalNews 临床招募新闻
     * @return 结果
     */
    @Override
    public int insertClinicalNews(ClinicalNews clinicalNews)
    {
        clinicalNews.setCreateTime(DateUtils.getNowDate());
        clinicalNews.setCreateBy(ShiroUtils.getSysUser().getLoginName());
        return clinicalNewsMapper.insertClinicalNews(clinicalNews);
    }

    /**
     * 修改临床招募新闻
     * 
     * @param clinicalNews 临床招募新闻
     * @return 结果
     */
    @Override
    public int updateClinicalNews(ClinicalNews clinicalNews)
    {
        clinicalNews.setUpdateTime(DateUtils.getNowDate());
        clinicalNews.setUpdateBy(ShiroUtils.getSysUser().getLoginName());
        clinicalNews.setUpdateName(ShiroUtils.getSysUser().getUserName());
        return clinicalNewsMapper.updateClinicalNews(clinicalNews);
    }

    /**
     * 批量删除临床招募新闻
     * 
     * @param ids 需要删除的临床招募新闻主键
     * @return 结果
     */
    @Override
    public int deleteClinicalNewsByIds(String ids)
    {
        return clinicalNewsMapper.deleteClinicalNewsByIds(Convert.toStrArray(ids),ShiroUtils.getSysUser().getLoginName());
    }

    /**
     * 删除临床招募新闻信息
     * 
     * @param id 临床招募新闻主键
     * @return 结果
     */
    @Override
    public int deleteClinicalNewsById(Long id)
    {
        return clinicalNewsMapper.deleteClinicalNewsById(id,ShiroUtils.getSysUser().getLoginName());
    }

    @Override
    public void updateclinicalNewsBrowseNum(Long id)
    {
        clinicalNewsMapper.updateclinicalNewsBrowseNum(id);
    }

    /*
     * 根据id查询上一篇下一篇
     * */
    @Override
    public AjaxResult getUpandDown(Long id){
        AjaxResult ajaxResult = new AjaxResult();
        try{
            List<HashMap<String, Object>> upandDown = clinicalNewsMapper.getUpandDown(id);
            ajaxResult.put("data",upandDown);
            ajaxResult.put("code","200");
            ajaxResult.put("msg","查询成功！");
        }catch (Exception e){
            e.printStackTrace();
            ajaxResult.put("code","500");
            ajaxResult.put("msg","获取新闻上下篇失败，请联系管理员！");
        }
        return ajaxResult;
    }
}
